package com.lagou.framework.util;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author srh
 * @date 2020/04/02
 **/
public class ThreadPoolUtil {

    private static ThreadPoolExecutor executor = init();

    public static ThreadPoolExecutor getExecutor() {
        return executor;
    }

    public void execute(Runnable runnable) {
        executor.execute(runnable);
    }

    private static ThreadPoolExecutor init() {
        return new ThreadPoolExecutor(4, 8, 3, TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(10), Executors.defaultThreadFactory(), new ThreadPoolExecutor.AbortPolicy());
    }

}
